package folder.main.exp1.algorithms;

import java.util.Comparator;

import folder.model.network.Network;
import folder.model.network.NetworkPaths;
import folder.model.node.Node;

public class Balanced extends Algorithm1
{	
	// Algorithm
	
	public static Balanced balanced( Network networkPath, int numberNodesSpecial )
	{
		return new Balanced( networkPath, numberNodesSpecial );
	}
	
	public Balanced( Network networkPath, int numberNodesSpecial )
	{
		super( networkPath, numberNodesSpecial );
		
		this.comparator = new ComparatorBalanced();
		
		this.runAlgorithm();
	}
	
	// Comparator
	
    private class ComparatorBalanced implements Comparator< Node >
    {   
    	@Override
    	public int compare( Node nodeX, Node nodeY )
    	{
    		Double balancedNodeX = nodeX.getDelayToNodeTargetMean() * nodeX.getDelayToNodeTargetMean() * nodeX.getNumberPaths();
    		Double balancedNodeY = nodeY.getDelayToNodeTargetMean() * nodeY.getDelayToNodeTargetMean() * nodeY.getNumberPaths();
    		
    		return balancedNodeX.compareTo( balancedNodeY );
    	}
    }

}
